home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / gfx / lise2.1 / lise / src / devclr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-31  |  1.2 KB  |  44 lines

  1. /*
  2.    this small programm should clear the communication line specified 
  3.    It uses the UNIX fork() system call to avaoid stuck on read.
  4.    Thus, this program is NOT AVAILABLE AT THE AMIGA at the time.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <sys/types.h>
  9. #include <signal.h>
  10. #include <strings.h>
  11. #include <auxcfg.h>
  12.  
  13. #define  FLAGFILE   /tmp/devclr.flg
  14.  
  15. main(argc,argv)
  16. int argc;
  17. char *argv[];
  18. {
  19. int i,n,m,fd,pid;
  20. char c,s[80],z[80],a[80];
  21.  
  22.    if(argc!=2) {
  23.       printf("This program should be used to clear communication lines to\n");
  24.       printf("auxillary devices. You must specify the device entry for\n");
  25.       printf("the Aux_Config file.\n");
  26.       printf("To avoid printing of all character from the line to your\n");
  27.       printf("terminal, redirection to /dev/null is recommended\n");
  28.       exit(-1);
  29.    }
  30.    fd=auxopen(argv[1]);
  31.    printf("reading from line %s\n",auxparams[0]);
  32.    
  33.    pid=fork();
  34.    if(pid==0) {        /* child process reads the line */
  35.       while(1==1) {
  36.          read(fd,&c,1);
  37.          printf("%c",c); fflush(stdout);
  38.       }
  39.    } else {   /* here we have the parent process, which essentially sleeps */
  40.          sleep(2);
  41.      n=kill(pid,SIGKILL); /* we should get rid of our child now */
  42.    }
  43. }
  44.